package com.ywu.application.standard.tenant.api;

import com.ywu.common.result.CommonResult;
import com.ywu.application.standard.tenant.dto.TenantDto;
import com.ywu.application.standard.tenant.dto.TenantUserDTO;
import com.ywu.application.standard.tenant.entity.TenantEntity;
import com.ywu.application.standard.tenant.service.TenantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName TenantApi
 * @Description TODO
 * @Author GroundDemo
 * @Date 2024/5/3 14:44
 * @Version 1.0
 **/
@RestController
@RequestMapping("/ywu/tenant")
public class TenantApi {
    @Autowired
    private TenantService tenantService;

    /**
    * @Author GroundDemo
    * @Description 添加租户信息
    * @Date 17:13 2024/5/3
    * @Param []
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/tenant.info.create")
    public CommonResult<Object> addTenantInfo(@RequestBody TenantDto tenantDto) {
        return tenantService.addTenantInfo(tenantDto);
    }

    /**
    * @Author GroundDemo
    * @Description 更新租户信息
    * @Date 17:15 2024/5/3
    * @Param [tenantDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/tenant.info.update")
    public CommonResult<Object> updateTenantInfo(@RequestBody TenantDto tenantDto) {
        return tenantService.updateTenantInfo(tenantDto);
    }

    /**
    * @Author GroundDemo
    * @Description 删除租户信息
    * @Date 17:17 2024/5/3
    * @Param [tenantDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/tenant.info.delete")
    public CommonResult<Object> deleteTenantInfo(@RequestBody TenantDto tenantDto) {
        return tenantService.deleteTenantInfo(tenantDto);
    }

    /**
    * @Author GroundDemo
    * @Description 查询租户信息列表
    * @Date 17:18 2024/5/3
    * @Param [tenantDto]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/tenant.info.query")
    public CommonResult<Object> queryTenantInfo(@RequestBody TenantDto tenantDto) {
        return tenantService.queryTenantInfo(tenantDto);
    }

    /**
    * @Author GroundDemo
    * @Description 租户授权
    * @Date 22:26 2024/5/23
    * @Param [tenantUserDTO]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/tenant.user.authorize")
    public CommonResult<Object> tenantUserAuthorize(@RequestBody TenantUserDTO tenantUserDTO) {
        return tenantService.tenantUserAuthorize(tenantUserDTO);
    }

    /**
     * @Author GroundDemo
     * @Description 删除租户授权
     * @Date 22:26 2024/5/23
     * @Param [tenantUserDTO]
     * @return com.ywu.common.result.CommonResult<java.lang.Object>
     **/
    @PostMapping("/tenant.user.auth.delete")
    public CommonResult<Object> tenantUserAuthDelete(@RequestBody TenantUserDTO tenantUserDTO) {
        return tenantService.tenantUserAuthDelete(tenantUserDTO);
    }

    /**
    * @Author GroundDemo
    * @Description 查询租户授权信息
    * @Date 22:44 2024/5/23
    * @Param [tenantUserDTO]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/tenant.user.authorize.info")
    public CommonResult<Object> tenantUserAuthorizeInfoQuery(@RequestBody TenantUserDTO tenantUserDTO) {
        return tenantService.tenantUserAuthorizeInfoQuery(tenantUserDTO);
    }

    /**
    * @Author GroundDemo
    * @Description 根据用户ID查询该用户下的所有租户
    * @Date 21:40 2024/5/30
    * @Param [tenantUserDTO]
    * @return com.ywu.common.result.CommonResult<java.util.List<com.ywu.tenant.standard.entity.TenantEntity>>
    **/
    @PostMapping("/tenant.info.by.user.id.spi")
    public CommonResult<List<TenantEntity>> queryTenantInfoByUserId(@RequestBody TenantUserDTO tenantUserDTO) {
        return tenantService.queryTenantInfoByUserId(tenantUserDTO);
    }

    /**
    * @Author GroundDemo
    * @Description 根据租户ID查询租户信息
    * @Date 19:47 2024/5/31
    * @Param [tenantDto]
    * @return com.ywu.common.result.CommonResult<com.ywu.tenant.standard.entity.TenantEntity>
    **/
    @PostMapping("/tenant.info.by.tenant.id.spi")
    public CommonResult<TenantEntity> queryTenantInfoByTenantId(@RequestBody TenantDto tenantDto) {
        return tenantService.queryTenantInfoByTenantId(tenantDto);
    }

    /**
    * @Author GroundDemo
    * @Description 根据用户ID删除租户授权信息
    * @Date 19:32 2025/3/26
    * @Param [tenantUserDTO]
    * @return com.ywu.common.result.CommonResult<java.lang.Object>
    **/
    @PostMapping("/tenant.info.delete.by.user.id.for.spi")
    public CommonResult<Object> deleteTenantPermission(@RequestBody TenantUserDTO tenantUserDTO) {
        return tenantService.deleteTenantPermission(tenantUserDTO);
    }
}
